Skip to main content

Create dummy variables by using the recode command

There is more than one way to make dummy variables (values 1 and 0). Perhaps the most basic way is by using the generate and replace commands (see one of the other examples).

An alternative way of making dummy variables is by using the destring and recode commands as illustrated in the example below.

The variable gender takes the values "1" and "2" representing the values “Male” and “Female” respectively. The result of the procedure is a variable containing the values 1 and 0 representing male and female (= not male) respectively.

Since the gender variable has alfanumeric value format, one must first convert to numeric format through the destring command.

 //Connect to datastore
require no.ssb.fdb:23 as db

create-dataset demography
import db/BEFOLKNING_KJOENN as gender

destring gender
tabulate gender
recode gender (2 = 0)
rename gender male

//Check for correct recoding
tabulate male, nolabels